"""
This Script takes a series of *.txt files and rename them starting at 00000 
"""
import shutil
import string
import os

path = 'E:\\Chile_2012\\Villarica\\11Feb2012\\DOAS\\Scanning\\11122012 scan3 (Los Crateres)'
i = 0
f = string.Formatter()
SOURCE = r"E:\Chile_2012\Villarica\11Feb2012\DOAS\Scanning\11122012 scan3 (Los Crateres)"
BACKUP = r"E:\Chile_2012\Villarica\11Feb2012\DOAS\Scanning\11122012 scan3 (Los Crateres)-bak"
shutil.copytree(SOURCE, BACKUP)
b = sorted (os.listdir(BACKUP))
s = sorted (os.listdir(SOURCE)) 
print b

for filename in s:
    prefix= filename[:-9]
    num = f.format("{0:05d}",i)
    new_filename = prefix + "_" + num +".txt"
    os.rename(os.path.normpath(os.path.join(path, filename)), os.path.normpath(os.path.join(path, new_filename)))
    i+=1
   